package cn.lili.controller.promotion;

import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.promotion.entity.dos.ReturnActivity;
import cn.lili.modules.promotion.entity.enums.ReturnActivityStatusEnum;
import cn.lili.modules.promotion.entity.enums.ReturnActivityTimeEnum;
import cn.lili.modules.promotion.service.ReturnActivityService;
import cn.lili.modules.system.client.DictionaryClient;
import cn.lili.modules.system.entity.dos.Dictionary;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@Api(tags = "全返卷面额")
@RequestMapping("/promotion/return/activity")
@RequiredArgsConstructor
public class ReturnActivityController {

    private final ReturnActivityService returnActivityService;

    private final DictionaryClient dictionaryClient;

    @ApiOperation(value = "全返卷有效时间")
    @GetMapping("/getActivityTime")
    public ResultMessage<Map<String,String>> getActivityTime() {
        return ResultUtil.data(ReturnActivityTimeEnum.convertMap());
    }

    @ApiOperation(value = "获取全返卷面额列表")
    @GetMapping
    public ResultMessage<Page<ReturnActivity>> getPage(ReturnActivity queryParam, PageVO page) {
        return ResultUtil.data(returnActivityService.getPage(queryParam, page));
    }

    @PostMapping
    @ApiOperation(value = "添加全返卷面额")
    public ResultMessage<Boolean> save(@RequestBody ReturnActivity saveParam) {
        saveParam.setStatus(ReturnActivityStatusEnum.PUBLISH_WAIT.getCode());
        return ResultUtil.data(returnActivityService.save(saveParam));
    }

    @ApiOperation(value = "编辑全返卷面额")
    @PutMapping
    public ResultMessage<Boolean> update(@RequestBody ReturnActivity updateParam) {
        return ResultUtil.data(returnActivityService.updateById(updateParam));
    }

    @ApiOperation(value = "发布全返卷面额")
    @PutMapping("/already/{id}")
    public ResultMessage<Boolean> already(@PathVariable String id) {
        return ResultUtil.data(returnActivityService.already(id));
    }

    @ApiOperation(value = "删除全返卷面额")
    @DeleteMapping(value = "/{id}")
    public ResultMessage<Boolean> removeById(@PathVariable String id) {
        return ResultUtil.data(returnActivityService.removeById(id));
    }

    @ApiOperation(value = "获取全返券活动开关")
    @GetMapping(value = "/getReturnActivityPromotion")
    public ResultMessage<Object> getReturnActivityPromotion () {
        Dictionary dictionary = dictionaryClient.getDict(Dictionary.builder().code("green_score_return").build());
        if (null == dictionary) {
            return ResultUtil.data("0");
        }else {
            return ResultUtil.data(dictionary.getValue());
        }
    }
}
